<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="utf-8" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=no"
    />
	<title>百度网盘秒传链接批量转存</title>
    <link
      rel="stylesheet"
      href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css"
    />
    <script src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js"></script>
    <script
      src="https://cdn.staticfile.org/popper.js/1.14.7/umd/popper.min.js"
      integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1"
      crossorigin="anonymous"
    ></script>
    <script
      src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"
      integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
      crossorigin="anonymous"
    ></script>
	<script type="text/javascript" src="./dist/browser/json-url.js"></script>
<script type="text/javascript">
function atou(str) {
    return decodeURIComponent(escape(window.atob(str)));
}
function Trim(str){  
    return str.replace(/(^\s*)|(\s*$)/g, "");  
}  
function addbdstoken(){
var x=document.getElementById("save")
x.action="https://pan.baidu.com/api/rapidupload?app_id=250528&bdstoken="+ document.getElementById("bdstoken").value +"&channel=chunlei&clienttype=0&rtype=1&web=1"
}
function copy(){
const input = document.querySelector('#copy_script');
	input.select();
	if (document.execCommand('copy')) {
		document.execCommand('copy');
		alert('复制成功');
}
}
function getLinkMulti(){
if(document.getElementById('bdstoken').value == ""){
alert('未输入bdstoken');
return;
}
var links = document.getElementById('link').value.split('\n');
for(i=0;i<links.length;i++){
getLink(links[i]);
}
}
function getLink(link) {
if(document.getElementById('bdstoken').value == ""){
alert('未输入bdstoken');
return;
}
var bdpan = link.match(/bdpan:\/\/(.+)/);;
var pcs = link.match('BaiduPCS-Go');
var mengji = link.match(/.{32}#.{32}/);
var bdlink = link.match('bdlink(.+)');
var pan = link.match(/^pan:\/\//);
if (bdpan){
var de_b64 = atou(bdpan[1]);
var md5 = de_b64.match(/\|(.{32})\|/)[1];
var slicemd5 = de_b64.match(/\|([^\|]{32})$/)[1];
var file_length = de_b64.match(/\|([0-9]+)\|/)[1];
var file_name = de_b64.match(/^(.+\.[a-zA-Z]{1,9})\|/)[1];
saveFile(md5, slicemd5, file_length, file_name, bdpan);
}
else if (pcs){
var input = link;
var length = input.match(/length\=([0-9]+)/)[1];
var md5 = input.match(/\-md5\=(.{32})/)[1];
var slicemd5 = input.match(/\-slicemd5\=(.{32})/)[1];
var file_name = input.match(/\"(.+)\"/)[1];
saveFile(md5, slicemd5, length, file_name, pcs);

}
else if (mengji){
var input = link;
var md5 = input.match(/^(.{32})#/)[1];
var slicemd5 = input.match(/#(.{32})#/)[1];
var file_length = input.match(/#([0-9]+)#/)[1];
var file_name = input.match(/#[0-9]+#(.+)$/)[1];
file_name = Trim(file_name);
saveFile(md5, slicemd5, file_length, file_name, mengji);
}
else if (bdlink){
var bdlink1 = link.match('bdlink\=([a-zA-Z0-9\=\/\+]+\={0,2})[\#\?\&]?');
var bdlink2 = link.match('bdlink\=([a-zA-Z0-9\=\/\+]+\={0,2})$');
var de_b64;
if(bdlink1){
de_b64 = atou(bdlink1[1]);
if(de_b64.split('\n').length > 1)
for (i=0;i<de_b64.split('\n').length;i++)
getLink(de_b64.split('\n')[i])
else if(de_b64.split('\n').length == 1)
getLink(de_b64);
}
else if(bdlink2){
var de_b64 = atou(bdlink2[1]);
if(de_b64.split('\n').length > 1)
for (i=0;i<de_b64.split('\n').length;i++){
getLink(de_b64.split('\n')[i])
}
else if(de_b64.split('\n').length == 1)
getLink(de_b64);
}
}
else if (pan){
const lib = JsonUrl('lzw');
lib.decompress(link.match(/^pan:\/\/(.+)/)[1]).then(output => {
for(i=0;i< output.length;i++){saveFile(output[i]['content-md5'],output[i]['slice-md5'],output[i]['content-length'],output[i]['path'],'pan');}})
}
else{
alert('未检测到有效秒传链接');
return;
}
}
function saveFile(md5,slicemd5,length,name,method){
var saveForm = document.createElement("form");
document.body.appendChild(saveForm);
saveForm.method = 'POST';
saveForm.target = '_blank';
saveForm.action = "https://pan.baidu.com/api/rapidupload?app_id=250528&bdstoken="+ document.getElementById("bdstoken").value +"&channel=chunlei&clienttype=0&rtype=1&web=1";
var path = document.createElement("input");
path.setAttribute("type", "hidden");
path.setAttribute("name", "path");
saveForm.appendChild(path);
if (method == 'pcs'){
path.setAttribute("value",  name)
}
else
{
path.setAttribute("value",'/' + name)
}
var md5_input = document.createElement("input");
md5_input.setAttribute("type", "hidden");
md5_input.setAttribute("name", "content-md5");
saveForm.appendChild(md5_input);
md5_input.setAttribute("value", md5);
var slice_md5 = document.createElement("input");
slice_md5.setAttribute("type", "hidden");
slice_md5.setAttribute("name", "slice-md5");
saveForm.appendChild(slice_md5);
slice_md5.setAttribute("value", slicemd5);
var file_length = document.createElement("input");
file_length.setAttribute("type", "hidden");
file_length.setAttribute("name", "content-length");
saveForm.appendChild(file_length);
file_length.setAttribute("value", length);
saveForm.submit();
}
</script>
</head>
<body>
    <div id="app">
      <div id="container" class="container">
        <div class="row">
<div class="col-sm-8 offset-sm-2 col-md-6 offset-md-3 text-center">
<h1>百度网盘秒传链接批量转存</h1>
<p>v0.2</p>
<p>
<b>请先阅读使用教程</b></br><a href='./manual.html' target=_blank><b>本站使用教程</b></a></br></p>
<p><a href='./index.html'>秒传链接在线转存</a></br>
<a href='./gen.html'>秒传链接在线生成</a></br>
<a href='./convert.html'>秒传链接在线转换</a></p>
<p><b>批量转存必读</b>
</br>
<b>请允许本站弹出多个窗口以实现批量请求</b></br>
<img src="https://s1.ax1x.com/2020/05/10/Y1OqX9.png" height="212">
</p>
</br>
复制代码，粘贴到<a href="https://pan.baidu.com/disk/home" target=_blank>百度网盘</a>地址栏，运行获取bdstoken</br>
如果代码开头的 <b>javascript:</b> 消失，请手动添加 <b>javascript:</b></br>



</div>
<div class="col-sm-8 offset-sm-2 col-md-6 offset-md-3 text-center">
<p><input class="form-control" id="copy_script" value="javascript:for(i=0;i < document.getElementsByTagName('script').length;i++){var scripts=document.getElementsByTagName('script')[i].innerHTML.match(/\'bdstoken\'\, \'(\w{32})\'/);if(scripts!=null){var bdstoken=scripts[0].match(/\'bdstoken\'\, \'(\w{32})\'/)[1];}}const input=document.createElement('input');document.body.appendChild(input);input.setAttribute('value',bdstoken);input.select();if(document.execCommand('copy')){document.execCommand('copy');alert('bdstoken '+bdstoken+'\n复制成功');}document.body.removeChild(input);">
</p>
<button class="btn btn-primary" id="copy" onclick=copy();>复制代码</button>

</div>

<div id="body" class="col-sm-8 offset-sm-2 col-md-6 offset-md-3 text-center">

  <div>
    </br><label for="bdstoken">bdstoken（必填）</label>
    <p><input name="bdstoken" class="form-control" id="bdstoken" placeholder="32位"></p>
  </div>
  <div>
  <label for="link">秒传链接</label>
  <p><textarea name="link" id="link" class="form-control" placeholder="bdpan... / BaiduPCS-Go ... / 5b1...#b3a... " rows=6></textarea></p>
  </div>
  <p><button onclick=getLinkMulti(); class="btn btn-primary">解析链接并转存</button></p>
  
</div>
<div id="footer" class="col-sm-8 offset-sm-2 col-md-6 offset-md-3 text-center">
<p>显示 {"errno":2} 为保存失败，检查输入的内容是否正确</br>{"errno":404} 为服务器无对应文件</br>{"errno":-6} 为未登录</br>{"errno":0} 为保存成功
</br>
<b>所有请求在用户端进行，本站不保存任何链接</b>
</p>
</div>
</div>
</div></div></div>
</body>
